﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Reflection;
using Epam.PhotoGallery.Interfaces.DataTransferObjects;
using System.Drawing;
using Epam.PhotoGallery.Site.CustomModelBinders;

namespace Epam.PhotoGallery.Site.CustomModelBinders
{
    //TODO: ADD Category model binder
    //assign with topic 
    //finish topic model binding

    public class TopicModelBinder : DefaultModelBinder
    {
        private const string PROPERTY_NAME_CREATION_DATE = "CreationDate";
        private const string COMMENT_TEXT_NAME = "CommentText";
        private const string COMMENT_IMAGES_COLLECTION_NAME = "CommentImages";
        private const string COMMENT_IMAGES_URL_COLLECTION_NAME = "CommentImagesUrl";

        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var resultObj = base.BindModel(controllerContext, bindingContext);

            FillCreationDate(resultObj, bindingContext);

            return resultObj;
        }

        private void FillCreationDate(object resultObj, ModelBindingContext bindingContext)
        {
            PropertyInfo creationDateProperty = bindingContext.ModelType.GetProperty(PROPERTY_NAME_CREATION_DATE);

            creationDateProperty.SetValue(resultObj, DateTime.Now, null);
        }

    }
}